'''
Author: 13896370136 3361098@qq.com
Date: 2024-03-11 13:13:39
LastEditors: 13896370136 3361098@qq.com
LastEditTime: 2024-03-14 14:09:59
FilePath: \ShopExport\mainUi.py
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'untitled.ui'
##
## Created by: Qt User Interface Compiler version 6.3.2
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
    QMetaObject, QObject, QPoint, QRect,Signal,
    QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
    QFont, QFontDatabase, QGradient, QIcon,QAction,QTextCursor,
    QImage, QKeySequence, QLinearGradient, QPainter,
    QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QComboBox, QDialog,QFrame,
    QDialogButtonBox, QListView, QSizePolicy, QWidget, QVBoxLayout, QHBoxLayout, QLabel, 
    QToolBar,QStyle,QTextBrowser,QTextEdit,QAbstractScrollArea,
    QLineEdit, QPushButton, QTableWidget, QTableWidgetItem)
import os, time
import icon_rc as icon

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        p = QLabel()
        p.setPixmap(QPixmap(":icon/logo.png").scaled(24,24))
        t = QLabel("小妖数据转换工具")
        m = QLabel("请选择要转换的文件：")
        self.toolbar = QToolBar()
        self.toolbar.setIconSize(QSize(16,16))
        self.toolbar.addAction( QAction(QApplication.style().standardIcon(
                    QStyle.SP_TitleBarMinButton
                ), "最小化", self) )
        self.toolbar.addAction( QAction(QApplication.style().standardIcon(
                    QStyle.SP_TitleBarMaxButton
                ), "最大化", self) )
        self.toolbar.addAction( QAction(QApplication.style().standardIcon(
                    QStyle.SP_TitleBarCloseButton
                ), "关闭", self) )
        # 第一行
        h0 = QHBoxLayout()
        h0.setContentsMargins(5,5,5,5)
        h0.addWidget(p)
        h0.addWidget(t)
        h0.addStretch(1)
        h0.addWidget(self.toolbar)
        # 第二行
        self.fdb = myQComboBox()
        self.fbt = QPushButton("开始导出")
        self.tbt = QPushButton("浏览结果")
        # self.fbt.setEnabled(False)
        # self.tbt.setEnabled(False)
        h1 = QHBoxLayout()
        h1.setContentsMargins(5,5,5,5)
        h1.addWidget(QLabel("数据来源:"))
        h1.addWidget(self.fdb)
        h1.addStretch(1)
        h1.addWidget(self.fbt)
        h1.addWidget(self.tbt)
        # 第三行
        self.log = myQTextBrowser()
        h2 = QHBoxLayout()
        h2.setContentsMargins(5,5,5,0)
        h2.addWidget(self.log)
        # 第四行
        ver = QLabel("重庆网思科技 Ver:6")
        ver.setStyleSheet("color: rgb(200, 200, 200);font-size:10px;")
        h3 = QHBoxLayout()
        h3.setContentsMargins(5,0,5,5)
        h3.addStretch(1)
        h3.addWidget(ver)

        v = QVBoxLayout(self)
        v.setContentsMargins(0,0,0,0)
        v.addLayout(h0)
        v.addLayout(h1)
        v.addLayout(h2)
        v.addLayout(h3)
        # v.addStretch(1)

class myQComboBox(QComboBox):
    def __init__(self):
        QComboBox.__init__(self)
        self.setMinimumWidth(220)
        self.setMinimumHeight(32)
        self.setIconSize(QSize(24,24))
        self.setStyleSheet("""
            QComboBox{border:1px solid gray;border-radius:3px;padding:1px 18px 1px 3px;min-width:6em;}
            QComboBox::drop-down{image:none;}
        """)
    def load(self, data):
        self.clear()
        [self.addItem(QIcon(i[0]), i[1]) for i in data]

class myQTextBrowser(QTextEdit):
    finished = Signal(int)
    def __init__(self):
        super().__init__()
        self.file = None
        self.place = None
        self.setReadOnly(True)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setLineWrapMode(QTextEdit.WidgetWidth)
        self.setSizeAdjustPolicy(QAbstractScrollArea.AdjustToContents)
    def info(self, data):
        self.insertHtml(f'<p style="color:green">{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {data}<p>\n')
        cur = self.textCursor()
        self.moveCursor(QTextCursor.End)
        return
    def wran(self, data):
        self.insertHtml(f'<p style="color:yellow">{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {data}<p>\n')
        cur = self.textCursor()
        self.moveCursor(QTextCursor.End)
        return
    def error(self, data):
        self.insertHtml(f'<p style="color:red">{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} {data}<p>\n')
        cur = self.textCursor()
        self.moveCursor(QTextCursor.End)
        return
    def debug(self, data):
        self.insertHtml(f'<p>{data}<p>\n')
        cur = self.textCursor()
        self.moveCursor(QTextCursor.End)
        return
    def lastRow(self,data):
        self.moveCursor(QTextCursor.PreviousRow)
        cur = self.textCursor()
        cur.deleteChar()
        self.insertHtml(f'{data}')
        self.moveCursor(QTextCursor.End)
        return
    def setpath(self, data):
        self.file = data # os.path.abspath(data)
        self.finished.emit(1)
    def setPlaces(self, data):
        self.place = data
        self.finished.emit(2)

class has_password(QDialog):
    def __init__(self):
        super().__init__()
        self.setWindowIcon(QIcon(":icon/huo.png"))
        self.setWindowTitle('登录后台')
        self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Tool)
        self.username = QLineEdit()
        self.password = QLineEdit()
        self.username.setPlaceholderText('用户名')
        self.password.setPlaceholderText('登录密码')
        self.password.setEchoMode(QLineEdit.Password)
        self.submit = QPushButton('提交')
        v = QVBoxLayout(self)
        v.setContentsMargins(10,10,10,10)
        v.setSpacing(20)
        v.addWidget(self.username)
        v.addWidget(self.password)
        v.addWidget(self.submit)

class has_place(QDialog):
    def __init__(self):
        super().__init__()
        self.data = None
        self.setWindowIcon(QIcon(":icon/huo.png"))
        self.setWindowTitle('选择门店')
        self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Tool)
        self.toolbar = QToolBar()
        self.toolbar.setOrientation(Qt.Vertical)
        v = QVBoxLayout(self)
        v.setContentsMargins(10,10,10,10)
        v.addWidget(self.toolbar)
    def setData(self, data):
        self.data = data
        self.toolbar.clear()
        for i in data:
            action = QAction(f'{i[1]}\n{i[2]}', self)
            action.setData(i[0])
            self.toolbar.addAction(action)